{% extends "base.html" %}
{% load i18n %}
{% block title %} Tu Negocio Empresarios - Agregar Prestamo a Empresario{% endblock %}

{% block head-css-ext %}
    <link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}css/layout.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}css/jquery-ui.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}css/ui.datepicker.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}css/jquery.autocomplete.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}css/forms.css" media="screen" />
{% endblock %}

{% block head-js-ext %}
    <!-- jQuery -->
    <script type="text/javascript" src="{{MEDIA_URL}}js/jquery.js"></script>
    <script type="text/javascript" src="{{MEDIA_URL}}js/jquery-ui.js"></script>
    <script type="text/javascript" src="{{MEDIA_URL}}js/jquery.ui.datepicker-es.js"></script>
    <!--[if IE]><script type="text/javascript" src="{{MEDIA_URL}}js/jquery.bgiframe.js"></script><![endif]-->
    <script type="text/javascript" src="{{MEDIA_URL}}js/jquery.autocomplete.js"></script>
{% endblock %}


{% block head-js-embedded %}
    <script type="text/javascript" charset="utf-8">
        $(document).ready(function(){
	  
            var year = new Date().getFullYear();
	  
            $("button, input:submit", ".enviar").button();
      
            $("#datepicker").datepicker({
                firstDay: 0,
                dateFormat: 'yy-mm-dd',
                yearRange: '1900' + ':' + year, 
                changeMonth: true,
                changeYear: true,
                showOn: 'button',
                buttonImage: '{{MEDIA_URL}}img/calendar.gif',
                buttonImageOnly: true,
                showButtonPanel: true,
                maxDate : new Date()
            });
      
            $('#productos').autocomplete("{% url buscarproducto %}", {
                multiple: true,
                dataType: 'json',
                width: 300,
                parse: function(data){
                    return $.map (data, function(row) {
                        return {
                            data: row,
                            result: row[0]
                        }
                    });
                }
            }).result(function(event, data, formatted) {
                $('#productos').val(data[0]);
            });  
        });  
    </script>
{% endblock %}

{% block content-box1 %}
    <b> Agregar Prestamo a {{ empresario }}</b>
    <br><br>
    <form method="post" action=".">{% csrf_token %}
        {% if form.non_field_errors %}
            <div class="error">{{ form.non_field_errors|join:", " }}</div>
            <br><br>
        {% endif %}	
        <table>
            <tr>
                <td><label for="productos">Producto:</label>{% if form.producto.errors %}<div class="error">{{ form.producto.errors|join:", " }}</div>{% endif %}</td>
                <td>{{ form.producto }}</td>
            </tr>
            <tr>
                <td><label for="id_cantidad">Cantidad:</label>{% if form.cantidad.errors %}<div class="error">{{ form.cantidad.errors|join:", " }}</div>{% endif %}</td>
                <td>{{ form.cantidad }}</td>        
            </tr>     
            <tr>
                <td><label for="id_fecha">Fecha Prestamo:</label>{% if form.fecha.errors %}<div class="error">{{ form.fecha.errors|join:", " }}</div>{% endif %}</td>
                <td>{{ form.fecha }}</td>
            </tr>
            <tr>
                <td><label for="id_tipo_prestamo">Tipo de Prestamo:</label>{% if form.tipo_prestamo.errors %}<div class="error">{{ form.tipo_prestamo.errors|join:", " }}</div>{% endif %}</td>
                <td>{{ form.tipo_prestamo }}</td>
            </tr>	  
            {{ form.empresario }}
        </table>
        <br>
        <div align="center" class="enviar">      
            <input type="submit" value="Agregar Prestamo a Empresario" />
        </div>
    </form>  
{% endblock %}

{% block content-colum2 %}
    {% if user.is_authenticated %}
        <ul>
            <li><a href="{% url index %}">{% trans "Home" %}</a></li>
            <li><a href="{% url empresarios %}">Empresarios</a></li>
            <li><a href="{% url listar_empresarios %}">Listar Empresarios</a></li>
        </ul>
    {% endif %}   
{% endblock %}